home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- * pixmapCursor.c:
- *
- * This demonstrates how in X to define a cursor for one's own application
- * without changing the cursor for the rest of the system. In X11, this
- * can be done using either Pixmaps, Fonts, or Glyphs. Study especially
- * the functions:
- *
- * XCreateFontCursor, XCreatePixmapCursor, XCreateGlyphCursor
- * XDefineCursor, XUndefineCursor
- *
- * See /usr/include/X11/cursorfont.h for some predefined Font Cursors.
- *
- * These change the cursor only for the Window they're defined for.
- * The following is an example using Pixmap cursors.
- */
-
- #include <stdio.h>
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
-
- #define xhair15_width 15
- #define xhair15_height 15
- #define xhair15_x_hot 7
- #define xhair15_y_hot 7
- static char xhair15_bits[] = {
- 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00,
- 0x00, 0x00, 0x3f, 0x7e, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00,
- 0x80, 0x00, 0x80, 0x00, 0x80, 0x00};
-
- #define xhair_width 16
- #define xhair_height 16
- #define xhair_x_hot 7
- #define xhair_y_hot 7
- static char xhair_bits[] = {
- 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
- 0x00, 0x00, 0x3f, 0xfc, 0x3f, 0xfc, 0x00, 0x00, 0x80, 0x01, 0x80, 0x01,
- 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01};
-
- #define xhair17_width 17
- #define xhair17_height 17
- #define xhair17_x_hot 8
- #define xhair17_y_hot 8
- static char xhair17_bits[] = {
- 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00,
- 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
- 0x7f, 0xfc, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00,
- 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00,
- 0x00, 0x01, 0x00};
- #define xhair30_width 30
- #define xhair30_height 30
- #define xhair30_x_hot 16
- #define xhair30_y_hot 13
- static char xhair30_bits[] = {
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x3f, 0xfe, 0x3f,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00};
-
- #define xhair31_width 31
- #define xhair31_height 31
- #define xhair31_x_hot 15
- #define xhair31_y_hot 15
- static char xhair31_bits[] = {
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0x3f, 0xfe, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00};
-
- #define xhair32_width 32
- #define xhair32_height 32
- #define xhair32_x_hot 16
- #define xhair32_y_hot 15
- static char xhair32_bits[] = {
- 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00,
- 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00,
- 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00,
- 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00,
- 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00,
- 0xff, 0x7f, 0xfe, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0x00, 0x80, 0x01, 0x00,
- 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00,
- 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00,
- 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00,
- 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00,
- 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00};
-
- #define xhair33_width 33
- #define xhair33_height 33
- #define xhair33_x_hot 16
- #define xhair33_y_hot 15
- static char xhair33_bits[] = {
- 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
- 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
- 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
- 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
- 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0xff, 0x3f, 0xf8, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
- 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
- 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
- 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
- 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
- 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00};
-
- #include <X11/bitmaps/xlogo32>
-
- main()
- {
- Display *dpy;
- Window wind;
- unsigned int scr;
- unsigned int keep_going = 1;
- XEvent ev;
- unsigned int i, j;
- const unsigned int MAX_curs = 8;
- XColor backg, ebackg, foreg, eforeg;
- XColor Red, eRed, Green, eGreen;
- Pixmap xHairs[MAX_curs];
- Cursor cHairs[MAX_curs];
- Window rwin;
- Colormap dcm;
- GC dgc;
- struct { unsigned char *bits; unsigned int w, h, hotx, hoty; } hairdefs[MAX_curs];
- static unsigned char *id[] = {"0", "1", "2", "3", "4", "5", "6", "7"};
- XWMHints wmhints;
- XSizeHints wmsizehints;
- XClassHint classhint;
-
- hairdefs[0].bits = xhair15_bits;
- hairdefs[0].w = xhair15_width;
- hairdefs[0].h = xhair15_height;
- hairdefs[0].hotx = xhair15_x_hot;
- hairdefs[0].hoty = xhair15_y_hot;
-
- hairdefs[1].bits = xhair_bits;
- hairdefs[1].w = xhair_width;
- hairdefs[1].h = xhair_height;
- hairdefs[1].hotx = xhair_x_hot;
- hairdefs[1].hoty = xhair_y_hot;
-
- hairdefs[2].bits = xhair17_bits;
- hairdefs[2].w = xhair17_width;
- hairdefs[2].h = xhair17_height;
- hairdefs[2].hotx = xhair17_x_hot;
- hairdefs[2].hoty = xhair17_y_hot;
-
- hairdefs[3].bits = xhair30_bits;
- hairdefs[3].w = xhair30_width;
- hairdefs[3].h = xhair30_height;
- hairdefs[3].hotx = xhair30_x_hot;
- hairdefs[3].hoty = xhair30_y_hot;
-
- hairdefs[4].bits = xhair31_bits;
- hairdefs[4].w = xhair31_width;
- hairdefs[4].h = xhair31_height;
- hairdefs[4].hotx = xhair31_x_hot;
- hairdefs[4].hoty = xhair31_y_hot;
-
- hairdefs[5].bits = xhair32_bits;
- hairdefs[5].w = xhair32_width;
- hairdefs[5].h = xhair32_height;
- hairdefs[5].hotx = xhair32_x_hot;
- hairdefs[5].hoty = xhair32_y_hot;
-
- hairdefs[6].bits = xhair33_bits;
- hairdefs[6].w = xhair33_width;
- hairdefs[6].h = xhair33_height;
- hairdefs[6].hotx = xhair33_x_hot;
- hairdefs[6].hoty = xhair33_y_hot;
-
- hairdefs[7].bits = xlogo32_bits;
- hairdefs[7].w = xlogo32_width;
- hairdefs[7].h = xlogo32_height;
- hairdefs[7].hotx = 10;
- hairdefs[7].hoty = 10;
-
- dpy = XOpenDisplay("");
- scr = DefaultScreen(dpy);
- rwin = RootWindow(dpy, scr);
- dcm = DefaultColormap(dpy, scr);
- dgc = DefaultGC(dpy,scr);
-
- for( i = 0; i < MAX_curs; i++ ) {
- xHairs[i] = XCreateBitmapFromData( dpy, rwin,
- hairdefs[i].bits, hairdefs[i].w, hairdefs[i].h);
- if( xHairs[i] == NULL ) {
- fprintf( stderr, "Error creating bitmap from data\n" );
- exit(1);
- }
- }
-
- if( !XAllocNamedColor(dpy, dcm, "darkslategray", &backg, &ebackg)) {
- fprintf( stderr, "Error getting darkslategray\n" ); exit(1); }
-
- if( !XAllocNamedColor(dpy, dcm,"ivory", &foreg, &eforeg)) {
- fprintf( stderr, "Error getting Ivory\n" ); exit(1); }
-
- if( !XAllocNamedColor(dpy, dcm, "red", &Red, &eRed)) {
- fprintf( stderr, "Error getting red\n" ); exit(1); }
-
- if( !XAllocNamedColor(dpy, dcm,"green", &Green, &eGreen)) {
- fprintf( stderr, "Error getting green\n" ); exit(1); }
-
- for( i = 0; i < MAX_curs; i++ ) {
- cHairs[i] = XCreatePixmapCursor(dpy, xHairs[i], xHairs[i], &Red, &Green,
- hairdefs[i].hotx, hairdefs[i].hoty);
- if( cHairs[i] == NULL ) {
- fprintf( stderr, "Error creating cursor from bitmap\n" );
- exit(1);
- }
- }
-
- wind = XCreateSimpleWindow( dpy, rwin, 0, 0, 512, 512, 2,
- foreg.pixel, backg.pixel);
- classhint.res_name = "LEFT or RIGHT Mouse to Change Cursor";
- classhint.res_class = "GlyphCursor";
- XSetClassHint(dpy, wind, &classhint);
-
- wmhints.input = True;
- wmhints.flags = InputHint;
- XSetWMHints(dpy, wind, &wmhints);
-
- wmsizehints.x = 100;
- wmsizehints.y = 100;
- wmsizehints.width = 100;
- wmsizehints.height = 100;
- wmsizehints.flags = USPosition | USSize;
- XSetWMNormalHints(dpy, wind, &wmsizehints);
-
- XSetForeground(dpy, dgc, foreg.pixel);
- XSelectInput( dpy, wind, ButtonPressMask|KeyPressMask|ExposureMask);
- XMapWindow( dpy, wind );
-
- i = 0;
- do {
- XNextEvent( dpy, &ev );
- switch( ev.type )
- {
- case Expose:
- XUndefineCursor( dpy, wind );
- XClearWindow(dpy, wind);
- XDefineCursor( dpy, wind, cHairs[i%MAX_curs] );
- XDrawString(dpy, wind, dgc, 200, 200, id[i%MAX_curs], strlen(id[i%MAX_curs]));
- break;
-
- case KeyPress:
- XCloseDisplay(dpy);
- keep_going = 0;
- break;
-
- case ButtonPress:
- if( ev.xbutton.button == Button1 )
- i += 1;
- else if( ev.xbutton.button == Button3 )
- i -= 1;
- else
- i = 0;
- XUndefineCursor( dpy, wind );
- XClearWindow(dpy, wind);
- XDefineCursor( dpy, wind, cHairs[i%MAX_curs] );
- XDrawString(dpy, wind, dgc, 200, 200, id[i%MAX_curs], strlen(id[i%MAX_curs]));
- break;
-
- default:
- break;
- }
- } while( keep_going );
- exit(0);
- }
-